//
// Created by Ryan on 2020/11/28.
//

#ifndef CCOS_ELF_H
#define CCOS_ELF_H

#include "types.h"
#include "multiboot.h"


#define ELF32_ST_TYPE(i) ((i)&0xf)


// elf格式区段头
typedef
struct 
{
    uint32_v name;
    uint32_v type;
    uint32_v flags;
    uint32_v addr;
    uint32_v offset;
    uint32_v size;
    uint32_v link;
    uint32_v info;
    uint32_v addralign;
    uint32_v entsize;
} __attribute__((packed)) elf_section_header_m;



// elf格式符号
typedef
struct 
{
    uint32_v name;
    uint32_v value;
    uint32_v size;
    uint8_v info;
    uint8_v other;
    uint16_v shndx;
}__attribute__((packed)) elf_symbol_m;


// elf信息
typedef
struct 
{
    elf_symbol_m *symtab;
    uint32_v symtabsz;
    const char *strtab;
    uint32_v strtabsz;
}elf_m;


// 从 multiboot_m 结构获取信息ELF
elf_m elf_from_multiboot(multiboot_m *mb);

// 查看的符号信息ELF
const char *elf_lookup_symbol(uint32_v addr, elf_m *elf);


#endif //CCOS_ELF_H
